/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VentanaPrincipal.java
 *
 * Created on 09-oct-2011, 16:13:05
 */
package Interfaz;
import java.util.*;
import java.io.*;
import Dominio.*;
import javax.swing.JOptionPane;

/**
 *
 * @author Usuario
 */
public class VentanaPrincipal extends javax.swing.JFrame {

    private SistemaCarne modelo;
    
    /** Creates new form VentanaPrincipal */
    public VentanaPrincipal(SistemaCarne unSistema) {
        
        modelo = unSistema;
        this.setLocation(500, 400);
        this.setBounds(500,400,500,400);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Fondo = new javax.swing.JLabel();
        jPLoginPMT = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        JBOK = new javax.swing.JButton();
        JtxtPMT = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jPLoginMedico1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        JBOK1 = new javax.swing.JButton();
        JtxtMedico = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBounds(new java.awt.Rectangle(100, 100, 450, 390));
        setMinimumSize(new java.awt.Dimension(450, 390));
        getContentPane().setLayout(null);

        Fondo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Interfaz/Flia feliz.png"))); // NOI18N
        getContentPane().add(Fondo);
        Fondo.setBounds(30, 80, 180, 180);

        jPLoginPMT.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPLoginPMT.setLayout(null);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("CI:");
        jPLoginPMT.add(jLabel1);
        jLabel1.setBounds(40, 50, 29, 14);

        JBOK.setText("OK");
        JBOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JBOKActionPerformed(evt);
            }
        });
        jPLoginPMT.add(JBOK);
        JBOK.setBounds(41, 82, 73, 23);
        jPLoginPMT.add(JtxtPMT);
        JtxtPMT.setBounds(102, 49, 70, 20);

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setText("Login Madre/Padre/Tutor");
        jPLoginPMT.add(jLabel2);
        jLabel2.setBounds(12, 13, 150, 14);

        getContentPane().add(jPLoginPMT);
        jPLoginPMT.setBounds(240, 180, 180, 140);

        jPLoginMedico1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPLoginMedico1.setLayout(null);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setText("CI Usuario:");
        jPLoginMedico1.add(jLabel3);
        jLabel3.setBounds(12, 47, 70, 14);

        JBOK1.setText("OK");
        JBOK1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JBOK1ActionPerformed(evt);
            }
        });
        jPLoginMedico1.add(JBOK1);
        JBOK1.setBounds(41, 82, 73, 23);
        jPLoginMedico1.add(JtxtMedico);
        JtxtMedico.setBounds(100, 45, 70, 20);

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel4.setText("Login  Medico");
        jPLoginMedico1.add(jLabel4);
        jLabel4.setBounds(51, 13, 89, 14);

        getContentPane().add(jPLoginMedico1);
        jPLoginMedico1.setBounds(240, 20, 180, 140);

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(51, 153, 0));
        jLabel5.setText("Sistema de Carnés de Salud");
        getContentPane().add(jLabel5);
        jLabel5.setBounds(10, 20, 220, 60);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void JBOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JBOKActionPerformed
        boolean existeMadre= modelo.ExistePersona(modelo.getListaMadres(), JtxtPMT.getText());
        if(existeMadre){
            VentanaListaCarnes listaCarne = new VentanaListaCarnes(modelo, false, JtxtPMT.getText());
            listaCarne.setVisible(true);
        }
        else{
            boolean existePadre= modelo.ExistePersona(modelo.getListaPadres(), JtxtPMT.getText());
            if (existePadre){
                VentanaListaCarnes listaCarne = new VentanaListaCarnes(modelo, false, JtxtPMT.getText());
                listaCarne.setVisible(true);
            }
            else{
                boolean existeTutor = modelo.ExistePersona(modelo.getListaTutores(), JtxtPMT.getText());
                if (existeTutor){
                    VentanaListaCarnes listaCarne = new VentanaListaCarnes(modelo, false, JtxtPMT.getText());
                listaCarne.setVisible(true);
                }
                else{
                    JOptionPane.showMessageDialog(null,"La persona no existe", "Error", 2);
                    JtxtPMT.setText("");
                }
            }
        }
            
           
       
       
    }//GEN-LAST:event_JBOKActionPerformed

    private void JBOK1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JBOK1ActionPerformed
       boolean existe= modelo.ExistePersona(modelo.getListaMedicos(), JtxtMedico.getText());
        if(!existe){
            JOptionPane.showMessageDialog(null,"El medico no existe", "Error", 2);
            JtxtMedico.setText("");
        }else{
            VentanaListaCarnes listaCarne = new VentanaListaCarnes(modelo, true, JtxtMedico.getText());
            listaCarne.setVisible(true);
        } 
    }//GEN-LAST:event_JBOK1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel Fondo;
    private javax.swing.JButton JBOK;
    private javax.swing.JButton JBOK1;
    private javax.swing.JTextField JtxtMedico;
    private javax.swing.JTextField JtxtPMT;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPLoginMedico1;
    private javax.swing.JPanel jPLoginPMT;
    // End of variables declaration//GEN-END:variables
}
